package net.kunyv.DAL;

import net.kunyv.entity.DbConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;



 public class DbSession
{
  public static synchronized Connection getConnection(DbConfig dbconfig) {
    Connection conn = null;
    try {
      Class.forName(dbconfig.getDriverClass());
      conn = DriverManager.getConnection(dbconfig.getUrl(), dbconfig.getUsername(), dbconfig.getPassword());
    } catch (Exception e) {
      e.printStackTrace();
     }
    return conn;
  }


   public static synchronized void closeConnection(Connection conn) {
    try {
      if (conn != null && !conn.isClosed())
        conn.close();
    } catch (SQLException e) {
      e.printStackTrace();
     }
  }
 }

